- issuable = local_assigns.fetch(:issuable)
- form = local_assigns.fetch(:form)

- return unless issuable.is_a?(MergeRequest)
- return if issuable.closed_or_merged_without_fork?

- source_title, target_title = format_mr_branch_names(@merge_request)

- vis010 = _('This merge request is from a private project to an internal project.')
- vis020 = _('This merge request is from a private project to a public project.')
- vis1020 = _('This merge request is from an internal project to a public project.')
- i18n = { '010' => vis010, '020' => vis020, '1020' => vis1020 }

- source_project = @merge_request.source_project
- target_project = @merge_request.target_project
- source_level = source_project.visibility_level
- source_visibility = source_project.visibility
- target_level = target_project.visibility_level

- visibilityMismatchString = i18n["#{source_level}#{target_level}"]

.form-group.row.d-flex.gl-px-5.branch-selector
  .align-self-center
    %span
      = html_escape(_('From %{code_open}%{source_title}%{code_close} into')) % { source_title: source_title, code_open: '<code>'.html_safe, code_close: '</code>'.html_safe }

    - if issuable.new_record?
      %code#js-target-branch-title{ data: { branch_name: @merge_request.target_branch } }= target_title
      &nbsp;
      = link_to _('Change branches'), mr_change_branches_path(issuable)
    - elsif issuable.for_fork?
      %code= issuable.target_project_path + ":"
    - if issuable.merged?
      %code= target_title
  - unless issuable.new_record? || issuable.merged?
    .merge-request-select.dropdown.gl-w-auto
      = form.hidden_field :target_branch
      = dropdown_toggle form.object.target_branch.presence || _("Select branch"), { toggle: "dropdown", 'field-name': "#{form.object_name}[target_branch]", 'refs-url': refs_project_path(@project, sort: 'updated_desc', find: 'branches'), selected: form.object.target_branch, default_text: _("Select branch") }, { toggle_class: "js-compare-dropdown js-target-branch monospace" }
      .dropdown-menu.dropdown-menu-selectable.js-target-branch-dropdown.target_branch.ref-name.git-revision-dropdown
        = dropdown_title(_("Select branch"))
        = dropdown_filter(_("Search branches"))
        = dropdown_content
        = dropdown_loading
- if source_level < target_level
  = render Pajamas::AlertComponent.new(variant: :warning, dismissible: false, alert_options: { class: 'gl-mb-4' }) do |c|
    - c.with_body do
      = visibilityMismatchString
      %br
      = _('Review the target project before submitting to avoid exposing %{source} changes.') % { source: source_visibility }
- elsif target_level > Gitlab::VisibilityLevel::PRIVATE
  - source_access_level = source_project.project_feature.repository_access_level
  - target_access_level =  target_project.project_feature.repository_access_level
  - if source_access_level < target_access_level
    = render Pajamas::AlertComponent.new(title: _('Should these changes be private?'), variant: :warning, dismissible: false, alert_options: { class: 'gl-mb-4' }) do |c|
      - c.with_body do
        - warning_message = html_escape(_("Project %{code_open}%{source_project}%{code_close} has more restricted access settings than %{code_open}%{target_project}%{code_close}. To avoid exposing private changes, make sure you're submitting changes to the correct project."))
        = warning_message % {code_open: '<code>'.html_safe, code_close: '</code>'.html_safe, source_project: source_project.name_with_namespace, target_project: target_project.name_with_namespace}

